/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-3-8 下午2:00
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.recycleviewdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.dqhl.recycleviewdemo.R;
import com.example.dqhl.recycleviewdemo.modle.SqlModle;

import java.util.List;

/**
 * Created by dqhl on 17/3/8.
 */
public class ListViewAdapter extends BaseAdapter {
    private List<SqlModle> mModleList;
    private Context mContext;
    private LayoutInflater inflater;

    public ListViewAdapter(Context context,List<SqlModle> mModleList){
        this.mContext = context;
        this.mModleList = mModleList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mModleList.size();
    }

    @Override
    public Object getItem(int position) {
        return mModleList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder viewHolder = null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.linearout_item,parent,false);
        }

        viewHolder.tv_dateId.setText(mModleList.get(position).getId());
        viewHolder.tv_dateName.setText(mModleList.get(position).getName());
        viewHolder.tv_dateAge.setText(mModleList.get(position).getAge());

        return convertView;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv_dateId;
        TextView tv_dateName;
        TextView tv_dateAge;


        public MyViewHolder(View view) {
            super(view);
            tv_dateId = (TextView) view.findViewById(R.id.tv_dateId);
            tv_dateName = (TextView) view.findViewById(R.id.tv_dateName);
            tv_dateAge = (TextView) view.findViewById(R.id.tv_dateAge);
        }
    }
}
